home *** CD-ROM | disk | FTP | other *** search
/ C++ für Kids / C++ for kids.iso / Buch / Monster7.cpp < prev    next >
C/C++ Source or Header  |  1999-01-21  |  2KB  |  83 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl\vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "Monster7.h"
  6. //---------------------------------------------------------------------------
  7. #pragma resource "*.dfm"
  8.  
  9. const String Pfad = "c:\\cpp\\buch\\";
  10.  
  11. class TMonster
  12. {
  13. public:
  14.   virtual void Erscheinen(String Bild);
  15. };
  16.  
  17. //---------------------------------------------------------------------------
  18.  
  19. TMonster *WerWohl;
  20. bool Modus;
  21. int  Zufall;
  22. TForm1 *Form1;
  23.  
  24. //---------------------------------------------------------------------------
  25. __fastcall TForm1::TForm1(TComponent* Owner)
  26.     : TForm(Owner)
  27. {
  28. }
  29. //---------------------------------------------------------------------------
  30. void TMonster::Erscheinen (String Bild)
  31. {
  32.   String Name = Bild.SubString(1, Bild.Length()-4);
  33.   Form1->Image1->Picture->LoadFromFile (Pfad+Bild);
  34.   Form1->Panel1->Caption = Name;
  35. }
  36. //---------------------------------------------------------------------------
  37. void __fastcall TForm1::FormCreate(TObject *Sender)
  38. {
  39.   randomize ();
  40.   WerWohl = new TMonster;
  41.   Timer1->Interval = 500;
  42.   Timer1->Enabled = false;
  43.   Modus = true;
  44. }
  45. //---------------------------------------------------------------------------
  46. void __fastcall TForm1::Button1Click(TObject *Sender)
  47. {
  48.   if (Modus)
  49.   {
  50.     Timer1->Enabled = true;
  51.     Button1->Caption = "Stop";
  52.   }
  53.   else
  54.   {
  55.     Timer1->Enabled = false;
  56.     Button1->Caption = "Start";
  57.   }
  58.   Modus = !Modus;
  59. }
  60. //---------------------------------------------------------------------------
  61. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  62. {
  63.   Zufall = random(5);
  64.   switch (Zufall)
  65.   {
  66.     case 0:
  67.       WerWohl->Erscheinen ("Frank.bmp");
  68.       break;
  69.     case 1:
  70.       WerWohl->Erscheinen ("Albert.bmp");
  71.       break;
  72.     case 2:
  73.       WerWohl->Erscheinen ("Sigmund.bmp");
  74.       break;
  75.     case 3:
  76.       WerWohl->Erscheinen ("Jekyll.bmp");
  77.       break;
  78.     case 4:
  79.       WerWohl->Erscheinen ("Hyde.bmp");
  80.   }
  81. }
  82. //---------------------------------------------------------------------------
  83.